package com.wuzuqing.android.eightdiagrams

import android.widget.TextView
import com.wuzuqing.android.eightdiagrams.base.BaseAdapter
import com.wuzuqing.android.eightdiagrams.base.BaseViewHolder
import com.wuzuqing.android.eightdiagrams.model.ITextItem

/**
 * @CopyRight: 广州仰望星空云科技有限公司
 * @Author : wuzuqing
 * @Email:wuzuqing@xinyu668.com
 * @CreateTime: 12.12.23 3:44 PM
 * @Description: 请写描述
 */


class TextItemAdapter : BaseAdapter<ITextItem>(R.layout.item_result) {
    private var choosePos = 0
    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        holder.getView<TextView>(R.id.text1).also {
            it.text = getItem(position)?.getText().orEmpty()
            it.setPadding(6,6,6,6)
            it.setBackgroundResource(if (choosePos == position) R.drawable.shape_choose else 0)
        }
    }


    override fun onClickPosition(position: Int) {
        super.onClickPosition(position)
        val old = choosePos
        choosePos = position
        notifyItemChanged(old)
        notifyItemChanged(choosePos)
    }
}